<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Area</title>
    <link rel="stylesheet" href="/Trees/LayUiBac/layui/css/layui.css" media="all">
</head>
<body>


<div class="layui-container">
    <div class="layui-row" style="border: cadetblue 1px solid;padding: 20px;margin-top: 30px">
        <h1>求救列表</h1>
        <table id="demo" lay-filter="thingTable"></table>
    </div>

</div>

<script src="/Trees/LayUiBac/layui/layui.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="meeting">进行会商</a>
</script>

<script>
    layui.use('table', function () {
        let $ = layui.$;
        let layer = layui.layer;
        let table = layui.table;
        //第一个实例
        let show = table.render({
            elem: '#demo'
            , url: '/Trees/thing?method=needHelp' //数据接口
            , page: false //开启分页
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "count": res.total, //解析数据长度
                    "data": res.list
                };
            }
            , cols: [[ //表头
                {field: 'time', title: '日期'}
                , {field: 'thingName', title: '事件名称'}
                , {
                    field: 'location', title: '发生位置', templet: function (d) {
                        return d.tClass.area;
                    }
                }
                , {field: 'method', title: '防治方案'}
                , {field: 'state', title: '目前状态'}
                , {fixed: 'right', align: 'center', toolbar: '#barDemo'}
            ]]
        })

        table.on('tool(thingTable)', function (obj) {
            let data = obj.data;
            console.log(data)
            let layEvent = obj.event;
            let tr = obj.tr;

            layer.open({
                type: 2
                , content: '/Trees/LayUiBac/home/expert/Jump/addMeet.html'
                , area: ['600px', '600px']
                , shade: ['0.9', '#393D49']
                , anim: 0
                , maxmin: true
                , btn: ["确认提交"]
                , yes: function (index, layero) {
                    let body = layer.getChildFrame('body', index);
                    let result = body.find("textarea[name=result]").val();
                    let expertName = body.find("textarea[name=expertName]").val();
                    let date = body.find("input[name=date]").val();
                    let str = "/Trees/meeting?method=add" + "&result=" + result + "&expertName=" + expertName + "&thingId=" + data.pkId+"&date="+date
                    console.log(str)
                    $.ajax({
                        type: 'get'
                        , url: str
                    })
                    layer.close(index);
                    show.reload();
                }
                , success: function (layero,index) {
                    let body = layer.getChildFrame('body', index);
                    body.find("input[name=thingName]").val(data.thingName)
                    body.find("input[name=time]").val(data.time)
                    body.find("input[name=area]").val(data.tClass.area)
                    body.find("input[name=describe]").val(data.describes)
                    body.find("input[name=size]").val(data.size)
                    body.find("input[name=thingId]").val(data.pkId)
                    console.log(data)
                }
            })
        })

    });
</script>

</body>
</html>